#pragma once
#include <pthread.h>
typedef void *(*func_t)(void *);

class thread
{
public:
    thread(func_t handle = nullptr, void *arg = nullptr) : _handle(handle), _arg(arg)
    {
    }

    bool push(func_t handle, void *arg)
    {
        //如果是空方法则返回插入错误
        if (!handle)
            return false;
        _arg = arg;
        _handle = handle;
        return true;
    }

    int create()
    {
        return pthread_create(&_tid, nullptr, _handle, _arg);
    }

    int detach()
    {
        return pthread_detach(_tid);
    }

    int join()
    {
        return pthread_join(_tid, nullptr);
    }

    ~thread()
    {
    }

private:
    pthread_t _tid;
    void *_arg;
    func_t _handle;
};
